import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
public class CaptureScreen {
    public static void test1() {
        int sum = 1;
        for (int i = 1; i <= 100; i++) {
            sum *= i;
            if (sum > 10000) {
                System.out.println(i + "," + sum);
                return;//方法结束
            }
        }
        System.out.println("over!");
    }

    public static void main(String[] args) throws Exception {
        Robot robot = new Robot();
        //设置Robot产生一个动作后的休眠时间,否则执行过快
        robot.setAutoDelay(1000);

        //获取屏幕分辨率
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        System.out.println(d);
        Rectangle screenRect = new Rectangle(d);
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss-SSS");
        //截图
        while (true) {
            BufferedImage bufferedImage = robot.createScreenCapture(screenRect);
            //保存截图
            File file = new File("D:\\Documents\\桌面\\TEST", df.format(new Date())+ ".png");
            ImageIO.write(bufferedImage, "png", file);
            System.out.println("over:"+file);
            Thread.sleep(1500);
        }
//        System.out.println(System.getProperties());
//        System.out.println(">>>>>>>>>>>>>>>>>>");
//        System.out.println(System.getenv());
//        System.out.println(System.getProperty("user.dir"));
//        test1();
//        System.out.println("main 结束了。。。");
//        System.out.println("看看看看");
//        System.out.println("等待你");
//        char c[]={1,2,46,77};
//        int i=10000;10000
        //c[0]=i;
    }
}
